import 'package:flutter/material.dart';
import 'package:untitled2/pages/class/ClassType.dart';
import 'package:untitled2/pages/home/HomePage.dart';
import 'package:untitled2/pages/msg/Message.dart';
import 'package:untitled2/pages/my/MyUser.dart';

class TabList extends StatefulWidget {
  int index;

  TabList({super.key, this.index = 3});

  @override
  State<TabList> createState() => _TabListState();
}

class _TabListState extends State<TabList> {
  int mCurrentIndex = 0;
  final List<Widget> _pages = const [HomePage(), ClassType(), MessagePage(), MessagePage(), MyUser()];

  @override
  void initState() {
    super.initState();
    mCurrentIndex = widget.index;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(
          'Flutter Demo',
          style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold),
        ),
        centerTitle: true,
        backgroundColor: Colors.blue,
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: mCurrentIndex,
        items: const [
          BottomNavigationBarItem(
            icon: Icon(Icons.home),
            label: "首页",
            backgroundColor: Colors.blue,
          ),
          BottomNavigationBarItem(icon: Icon(Icons.account_tree), label: "分类"),
          BottomNavigationBarItem(icon: Icon(Icons.access_time_filled), label: "消息"),
          BottomNavigationBarItem(icon: Icon(Icons.access_time_filled), label: "消息"),
          BottomNavigationBarItem(icon: Icon(Icons.account_circle_rounded), label: "我的"),
        ],

        onTap: (int index) {
          setState(() {
            mCurrentIndex = index;
          });
        },
        //       //选中的颜色
        // iconSize:35,           //底部菜单大小
        selectedItemColor: Colors.blue,
        // 选中项的颜色
        unselectedItemColor: Colors.black,
        type: BottomNavigationBarType.fixed,
        // fixedColor: Colors.blue,
      ),
      body: _pages[mCurrentIndex],
      floatingActionButton: ClipOval(
        child: FloatingActionButton(
          backgroundColor: Colors.white,
          onPressed: () {
            setState(() {
              mCurrentIndex = 2;
            });
          },
          child: Container(
            width: 60,
            height: 60,
            margin: const EdgeInsets.all(3),
            decoration: BoxDecoration(
              color: Colors.blue,
              borderRadius: BorderRadius.circular(30),
            ),
            child: const Icon(
              Icons.add,
              color: Colors.white,
            ),
          ),
        ),
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      drawer: Drawer(
          child: ListView(children: const [
        DrawerHeader(
            decoration: BoxDecoration(
              color: Colors.blue,
            ),
            child: Text(
              "DrawerHeader",
            ))
      ])),
      endDrawer: Drawer(
          child: ListView(children: const [
        DrawerHeader(
            decoration: BoxDecoration(
              color: Colors.blue,
            ),
            child: Text(
              "DrawerHeader",
            ))
      ])),
    );
    ;
  }
}

// class MyBottomNavigationBar extends StatefulWidget {
//   const MyBottomNavigationBar({super.key});
//
//   @override
//   State<MyBottomNavigationBar> createState() => _MyBottomState();
// }
//
// class _MyBottomState extends State<MyBottomNavigationBar> {
//
//
//   @override
//   Widget build(BuildContext context) {
//     return BottomNavigationBar(
//       currentIndex: mCurrentIndex,
//       items: const [
//         BottomNavigationBarItem(
//           icon: Icon(Icons.home),
//           label: "首页",
//           backgroundColor: Colors.blue,
//         ),
//         BottomNavigationBarItem(icon: Icon(Icons.account_tree), label: "分类"),
//         BottomNavigationBarItem(icon: Icon(Icons.access_time_filled), label: "消息"),
//         BottomNavigationBarItem(icon: Icon(Icons.account_circle_rounded), label: "我的"),
//       ],
//
//       //选中的颜色
//       // iconSize:35,           //底部菜单大小
//       selectedItemColor: Colors.blue,
//       // 选中项的颜色
//       unselectedItemColor: Colors.black,
//
//       // 未选中项的颜色
//       // selectedLabelStyle: const TextStyle(fontSize: 16),
//       // unselectedLabelStyle: const TextStyle(fontSize: 16),
//       type: BottomNavigationBarType.fixed,
//       // 点击时的高亮颜色
//       onTap: (int index) {
//         setState(() {
//           mCurrentIndex = index;
//         });
//       },
//     );
//   }
// }
